cd C:\Users\johannes.boehm\Dropbox\cenf\data\construction\rnd_intensity


use source_oecd.dta, clear

rename var1 industry

foreach country in kor jpn	swe	fin	aut	deu	svn	dnk	usa	bel	isl	fra	aus	nld	gbr	irl	cze	nor	hun	can	ita	est	esp	prt	tur	pol	svk	grc	mex	chl {
cap gen rnd_`country' = string(`country')
cap rename `country' rnd_`country'
cap drop `country'
}
reshape long rnd_ , i(industry) j(country) string

rename rnd_ rnd
replace rnd = "" if rnd == "#N/A"
destring rnd, replace

order ind_oecd, first

collapse (median) rnd ind_oecd, by(industry)

save rnd_oecd.dta, replace

use concordance_oecd_myagg.dta, clear

reshape long ind_oecd, i(myagg) j(index)
drop if ind_oecd==.

merge m:1 ind_oecd using rnd_oecd.dta
drop if _merge==2 // these are not really useful... "other services"
drop _merge

bysort myagg: egen rnd_myagg = mean(rnd)
duplicates drop myagg, force
drop rnd
drop industry index ind_oecd

sort myagg
rename rnd_myagg rnd_intensity

save rnd_myagg.dta, replace
